package com.mask.collections;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Random;

/**
 * ClassName ListDemo
 * Create by hx
 * Date 2021/9/15 10:46 上午
 */

public class ListDemo {
    public static void main(String[] args) {
        ArrayList<Double> list = new ArrayList<>(10);
        DecimalFormat doubleFormat = new DecimalFormat("0.00");
        //随机添加10个double类型元素到list中
        for (int i = 0; i < 10; i++) {
            list.add(Double.valueOf(doubleFormat.format(Math.random()*100)));
        }
        System.out.println("随机生成的10位double元素list为:");
        printList(list);
        //获取索引位5的元素
        System.out.println();
        Double indexFive = list.get(5);
        System.out.println("索引为5的元素为"+indexFive);
        //删除索引为3处的元素
        list.remove(3);
        System.out.println("删除索引为3的元素后的list:");
        printList(list);
    }
    private static void printList(ArrayList<Double> list){
        for (Double item : list){
            System.out.print(item + " ");
        }
    }
}
